﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace dsjsports
{
    public class Sportsmen : SynchronizationIObject
    {
        public Sportsmen(int ID, string name, string middleName, string lastName, SportsRank sportsRank, DateTime dateOfBirth, Floor floor, string sity, string clab)
        {
            this.id = ID;
            this.name = name;
            this.lastName = lastName;
            this.middleName = middleName;
            this.sportsRank = sportsRank;
            this.dateOfBirth = dateOfBirth;
            this.floor = floor;
            this.sity = sity;
            this.clab = clab;
        }

        private int id;
        public int ID
        {
            get { return id; }
        }


        private string name;
        public string Name
        {
            get { return name; }
            set
            {
                name = value;
                OnSportsmenChanged(new SportsmenChangedEventArgs("имя", value));
            }
        }

        private string lastName;
        public string LastName
        {
            get { return lastName; }
            set 
            {
                lastName = value;
                OnSportsmenChanged(new SportsmenChangedEventArgs("фамилия", value));
            }
        }

        private string middleName;
        public string MiddleName
        {
            get { return middleName; }
            set
            {
                middleName = value;
                OnSportsmenChanged(new SportsmenChangedEventArgs("отчество", value));
            }
        }

        private SportsRank sportsRank;
        public SportsRank SportsRank
        {
            get { return sportsRank; }
            set 
            {
                sportsRank = value;
                OnSportsmenChanged(new SportsmenChangedEventArgs("разряд", value));
            }
        }

        private DateTime dateOfBirth;
        public DateTime DateOfBirth
        {
            get { return dateOfBirth; }
            set
            {
                dateOfBirth = value;
                OnSportsmenChanged(new SportsmenChangedEventArgs("дата_рождения", value));
            }
        }

        private Floor floor;
        public Floor Floor
        {
            get { return floor; }
            set
            {
                floor = value;
                OnSportsmenChanged(new SportsmenChangedEventArgs("пол", value));
            }
        }

        private string sity;
        public string Sity
        {
            get { return sity; }
            set 
            {
                sity = value;
                OnSportsmenChanged(new SportsmenChangedEventArgs("город", value));
            }
        }

        private string clab;
        public string Clab
        {
            get { return clab; }
            set
            {
                clab = value;
                OnSportsmenChanged(new SportsmenChangedEventArgs("клуб", value));
            }
        }

        public event SportsmenChangedEventHandler SportsmenChanged;
        
        public delegate void SportsmenChangedEventHandler(object sender, SportsmenChangedEventArgs a);

        protected virtual void OnSportsmenChanged(SportsmenChangedEventArgs e)
        {
            if (SportsmenChanged != null)
            {
                SportsmenChanged(this, e);
            }
        }

        override public string ToString()
        {
            return lastName + " " + name[0] + ". " + middleName[0] + ".";
        }

        private bool isActual = true;
        public bool IsActual
        {
            get { return isActual; }
            set
            {
                if (isActual != value)
                {
                    isActual = value;
                }
            }
        }
    }

    public class SportsmenChangedEventArgs : EventArgs
    {
        public SportsmenChangedEventArgs(string ModifiedField, object NewValue)
        {
            modifiedField = ModifiedField;
            newValue = NewValue;
        }

        private string modifiedField;
        public string ModifiedField
        {
            get { return modifiedField; }
        }

        private object newValue;
        public object NewValue
        {
            get { return newValue; }
        }
    }
}
